package com.hhsjtest.alipaydragview.impl;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hhsjtest.appdraglayout.alipay.DragItemView;
import com.hhsjtest.alipaydragview.R;

/**
 * @author Shaohua
 * @date [2021:01:18 10:03]
 * @Discription:
 */
public class DefaultDragItemView extends DragItemView<ItemInfo> {

    private TextView titleTv;
    private ImageView deleteBtn;
    private ImageView iconIv;


    public DefaultDragItemView(@NonNull Context context) {
        super(context);
    }

    public DefaultDragItemView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DefaultDragItemView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public int bindLayout() {
        return R.layout.layout_drag_item;
    }


    @Override
    public void createItem(DragItemView view, ItemInfo dragItemInfo) {
        titleTv = view.findViewById(R.id.title);
        iconIv = view.findViewById(R.id.image);
        deleteBtn = view.findViewById(R.id.delete);
    }

    @Override
    public View getDeleteView() {
        return deleteBtn;
    }

    @Override
    public View getAddView() {
        return null;
    }

    @Override
    public void updateData(ItemInfo dragItemInfo) {
        this.dragItemInfo = dragItemInfo;
        titleTv.setText(dragItemInfo.name);
        if (dragItemInfo.isVisible()) {
            setVisibility(VISIBLE);
        } else {
            setVisibility(INVISIBLE);
        }
    }

    @Override
    public void setEdit(boolean edit) {
        if (edit) {
            deleteBtn.setVisibility(VISIBLE);
            titleTv.setBackgroundColor(0x88888888);
            titleTv.setTextColor(0xFFFFFFFF);
            if (isFloatViewView()) {
                // TODO: 2021/1/29 当判断是拖拽的悬浮视图的时候，处理相关逻辑
            } else {
                // TODO: 2021/1/29   当不是拖拽的悬浮视图的时候，处理相关逻辑
            }
        } else {
            deleteBtn.setVisibility(GONE);
            titleTv.setBackgroundColor(0xFFFF0000);
            titleTv.setTextColor(0xFF000000);
        }
    }


    @Override
    public void visibleItem() {
        setVisibility(VISIBLE);
    }

    @Override
    public void inVisibleItem() {
        setVisibility(INVISIBLE);
    }
}
